import Vue from 'vue'
import App from './App.vue'
import http from '@/api/config' //@ 等价于 /src 这个目录，避免写麻烦又易错的相对路径
import router from "./router";
import store from './store';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './mock';
import VueWechatTitle from 'vue-wechat-title';
import './assets/iconfont/iconfont.css';
// import 'gridmanager-vue/css/gm-vue.css';
// import GridManager from 'gridmanager-vue'
Vue.prototype.$http=http;
Vue.config.productionTip = false;

Vue.use(ElementUI);
Vue.use(VueWechatTitle);
// Vue.use(GridManager);
console.log(process.env.NODE_ENV); // 打印结果为 'development'
router.beforeEach((to,from,next)=>{
  // 防止刷新后vuex里丢失token
  // if (to.meta.title) {
  //   document.title = to.meta.title;
  // }

  store.commit('getToken')
  const token=store.state.user.token;
  if(!token && to.name!=='default' && to.name !== 'login'){
    next({ name:'login' });
  }else{
    next();
  }
})

new Vue({
  router, //路由
  store,  //根实例存储,子组件通过this.$store访问
  render: h => h(App),  //App组件渲染，这里的h既是vm.$createElement,便是在vm._render这个阶段
  created() {
    store.commit('addMenu', router);
    this.$http.post('/wechat/baseConfig/searchPublishInfoByTypeCdes',['NEWS', 'NOTICE', 'CAROUSEL']).then(function (res){
      console.log(res);
    });
  }

}).$mount('#app') //$mount()为手动挂载
